﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using He.Common;

namespace He.Web.manage.ad
{
    public partial class position_list : He.Web.UI.Manage
    {
        public int pcount = 0;    //总条数
        public int page;          //当前页
        public int pagesize = SysKeys.MANAGE_PAGE_SIZE; //设置每页显示的大小

        protected void Page_Load(object sender, EventArgs e)
        {
            page = GetInt("page", 0);

            if (!Page.IsPostBack)
            {
                chkLoginLevel("viewAdPosition");
                RptBind("id>0");
            }
        }

        #region 数据绑定
        private void RptBind(string strWhere)
        {
            He.BLL.ad_position bll = new He.BLL.ad_position();
            rptList.DataSource = bll.GetPageList(pagesize, page, strWhere, "id asc");
            rptList.DataBind();
            pcount = bll.GetRecordCount(strWhere);
        }
        #endregion

        #region 显示广告类型
        protected string GetTypeName(string strId)
        {
            switch (strId)
            {
                case "1":
                    return "文字";
                case "2":
                    return "图片";
                case "3":
                    return "幻灯片";
                case "4":
                    return "动画";
                case "5":
                    return "视频";
                case "6":
                    return "代码";
                default:
                    return "其它";
            }
        }
        #endregion

        //删除
        protected void lbtnDel_Click(object sender, EventArgs e)
        {
            chkLoginLevel("delad_position");
            BLL.ad_position bll = new BLL.ad_position();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                int id = Convert.ToInt32(((Label)rptList.Items[i].FindControl("lb_id")).Text);
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("cb_id");
                if (cb.Checked)
                {
                    Model.ad_position model = bll.GetModel(id);
                    //SaveLogs("[广告管理]删除广告位：" + model.title);
                    //删除记录
                    bll.Delete(id);
                }
            }
            JscriptPrint("批量删除成功啦！", Request.RawUrl, "Success");
        }
    }
}